<!DOCTYPE html>
<html lang="en" style="height: 100%">
<head>
    <meta charset="UTF-8">
    <title>个人主页</title>
    <link rel="stylesheet" href="css/bootstrap.min.css">
    <script src="js/vue.js"></script>
    <script src="js/jquery-3.3.1.js"></script>
    <script src="js/bootstrap.min.js"></script>
</head>
<style>
    img{
        width: 242px;
        height: 200px;
        margin-right: 10px;
        object-fit: cover;
    }
</style>
<body style="height: 100%;">
    <nav class="navbar navbar-default">
        <div class="container-fluid">
            <!-- Brand and toggle get grouped for better mobile display -->
            <div class="navbar-header">
                <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
                    <span class="sr-only">Toggle navigation</span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
                <a class="navbar-brand" href="index.html">首页</a>
            </div>

            <!-- Collect the nav links, forms, and other content for toggling -->
            <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
                <ul class="nav navbar-nav">
                    <li><a href="#">用户主页</a></li>
                </ul>
                <div class="navbar-form navbar-left">
                    <div class="form-group">
                        <input type="text" class="form-control" placeholder="Search" id="search">
                    </div>
                    <button class="btn btn-default" onclick="mySearch()">搜索</button>
                </div>
                <ul class="nav navbar-nav navbar-right">
                    <li id="userpic"></li>
                    <li style="border-right:1px solid silver;"><a href="#">用户名:</a></li>
                    <li ><a href="mine.html" id="name1">请登录</a></li>
                    <li id="regBtn1">
                        <button  class="btn btn-default" data-toggle="modal" data-target="#regModal">注册</button>
                    </li>
                    <li id="logBtn1">
                        <button  class="btn btn-default" data-toggle="modal" data-target="#logModal">登录</button>
                    </li>
                </ul>
            </div><!-- /.navbar-collapse -->
        </div><!-- /.container-fluid -->
    </nav>
<!--<DIV class="container-fluid">-->
    <!--<DIV class="row row-offcanvas row-offcanvas-left">-->
        <DIV class="col-xs-6 col-sm-3 col-md-2 sidebar sidebar-offcanvas" style="border-right:1px solid silver;height: 100%" id="sidebar">
            <UL class="nav nav-sidebar">

                <LI><A style="color: gray;border-bottom: 1px solid silver" href="#" onclick="getMyCollects()">我的收藏</A></LI>
                <LI><A style="color: gray;border-bottom: 1px solid silver" href="#" onclick="getMyPurchase()">我的购买</A></LI>
                <LI><A style="color: gray;border-bottom: 1px solid silver" href="#" onclick="getMyImgs()">我发布的图片</A></LI>
                <LI><A style="color: gray;border-bottom: 1px solid silver" href="#" onclick="getMyAts()" id="myats">我的关注</A></LI>
                <LI><A style="color: gray;border-bottom: 1px solid silver" href="#" onclick="getMyFans()" id="myfans">我的粉丝</A></LI>
                <LI><A style="color: gray;border-bottom: 1px solid silver" href="#" onclick="getDepositView()">账号充值</A></LI>
                <LI><A class="accordion-toggle collapsed" style="color: gray;border-bottom: 1px solid silver" href="#" data-toggle="collapse" data-target="#mastersubmenu3">账号安全</A>
                    <UL class="nav collapse" id="mastersubmenu3" style="padding-left: 20px;">
                        <LI><A style="color: gray;border-bottom: 1px solid silver" href="#" onclick="updateUser()">修改账号信息</A></LI>
                        <LI><A style="color: gray;border-bottom: 1px solid silver" href="#" onclick="updatePassword()">修改密码</A></LI>
                    </UL>
                </LI>
                <LI><A style="color: gray;border-bottom: 1px solid silver" href="#" onclick="logout()">注销</A></LI>

                <!--<LI><A style="color: gray" href="changePassword.php">密码维护</A></LI>-->


            </UL>
            <h3 style="text-align: center" id="rightTitle"></h3>
            <div id="rightDiv">
                <table id="imgs2" class="table table-hover">

                </table>
            </div>
        </DIV>



        <DIV class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main " style="position: absolute">
            <table id="imgs" class="table table-hover">

            </table>
            <br>
            <br>
            <br>
            <table id="imgslow" class="table table-hover">

            </table>
            <div id="addHr"></div>
            <hr>
            <div style="text-align: center;" id="page">
                <nav aria-label="Page navigation">
                    <ul class="pagination pagination-lg" id="skips">
<!--                        <li>-->
<!--                            <a href="#" aria-label="Previous" onclick="" id="skippre">-->
<!--                                <span aria-hidden="true">&laquo;</span>-->
<!--                            </a>-->
<!--                        </li>-->
<!--                        <li><a id="skip1" href="#" onclick="">1</a></li>-->
<!--                        <li><a id="skip2" href="#" onclick="">2</a></li>-->
<!--                        <li><a id="skip3" href="#" onclick="">3</a></li>-->
<!--                        <li><a id="skip4" href="#" onclick="">4</a></li>-->
<!--                        <li><a id="skip5" href="#" onclick="">5</a></li>-->
<!--                        <li>-->
<!--                            <a id="skipnex" href="#" aria-label="Next" onclick="">-->
<!--                                <span aria-hidden="true">&raquo;</span>-->
<!--                            </a>-->
<!--                        </li>-->
                    </ul>
                </nav>
                <style>
                    .c{
                        display:inline;
                    }
                </style>
                <div style="text-align: center">
                    <input  class="form-control c" type="number"style="width:60px;" id="toPageNum">
                    <button class="btn btn-default" id="toPageBtn" onclick="skipToPage()">跳转</button>
                </div>
                <h4>当前页数<span class="label label-default" id="curpage"></span></h4>
            </div>
        </DIV>
    <!--</DIV>-->
<!--</DIV>-->
    <div class="modal fade" id="regModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    注册
                </div>
                <div class="modal-body">
                    账号: <input type="text" class="form-control" name="name" id="regName">
                    密码：<input type="password" class="form-control" name="password" id="regPass1">
                    确认密码: <input type="password" class="form-control" name="password" id="regPass2">
                </div>
                <div class="modal-footer">
                    <button id="btn2" class="btn btn-default" onclick="reg()">注册</button>
                </div>
            </div>
        </div>
    </div>
</body>

<div class="modal fade" id="addTagsModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                添加标签
            </div>
            <div class="modal-body">
                标签名: <input type="text" class="form-control" name="tags" id="tags">
                (注:多个标签请用空格分隔开)
            </div>
            <div class="modal-footer">
                <button id="btn3" class="btn btn-default" onclick="hide()">关闭</button>
                <button id="btn4" class="btn btn-default" onclick="addTags2(staticId)">添加</button>
            </div>
        </div>
    </div>
</div>
<script src="js/checkToken.js"></script>
<script type="text/javascript">
    var userid=sessionStorage.getItem('id');
    var points=0;

    var pages=0;
    $("#search").bind("keypress", function(){
        if (event.keyCode == 13){
            // 触发需要调用的方法
            mySearch();
        }
    })

    $("#regModal").bind("keypress", function(){
        if (event.keyCode == 13){
            // 触发需要调用的方法
            reg();
        }
    })

    document.oncontextmenu = function(){
        return false;
    }

    var curpage=sessionStorage.getItem('page');
    console.log('当前页数：'+curpage);
    curpage=curpage==null?1:curpage;
    $('#toPageNum').val(curpage);

    function skipToPage() {
        var toPageNum=$('#toPageNum').val();
        skip(type,toPageNum);
    }

    $.ajax({
        url:'/hui/TestController/getPoints.do?userid='+userid,
        async:false,
        headers:{
            accessToken:localStorage.getItem('accessToken')
        },
        success:function (datas) {
            checkToken(datas);
            console.log('point:'+datas.result.point);
            points=datas.result.point;
        }
    })

    var page=1;
    var type='my';
    var search='';
    var userid=sessionStorage.getItem('id');
    console.log('userid:'+userid);
    var name=sessionStorage.getItem('name');
    var userpic=sessionStorage.getItem('pic');
    document.getElementById('curpage').innerText=page;
    // console.log('name='+name);
    if(name!='null') {
        document.getElementById('userpic').innerHTML='积分:'+points+'<img class="img-circle" src="/'+userpic+'" alt="" style="width: 50px;height: 50px">';
        document.getElementById('name1').innerText = name;
        document.getElementById('logBtn1').innerHTML='';
    }else{
        alert('请登录');
        window.location.href='index.html';
    }

    $.ajax({
        url:'/hui/TestController/getFans.do?userid='+userid,
        headers:{
            accessToken:localStorage.getItem('accessToken')
        },
        success:function (datas) {
            checkToken(datas);
            $.ajax({
                url:'/hui/TestController/getAt.do?userid='+userid,
                headers:{
                    accessToken:localStorage.getItem('accessToken')
                },
                success:function (data) {
                    checkToken(data);
                    console.log(data);
                    document.getElementById('myats').innerText='我的关注:'+data.result.length;
                    document.getElementById('myfans').innerText='我的粉丝:'+datas.result.length;
                }
            })
        }
    })

    function mySearch() {
        // document.getElementById('skippre').onclick=function () { skip("search",-1); };
        // document.getElementById('skipnex').onclick=function () { skip("search",0); };
        // document.getElementById('skip1').onclick=function () { skip("search",1); };
        // document.getElementById('skip2').onclick=function () { skip("search",2); };
        // document.getElementById('skip3').onclick=function () { skip("search",3); };
        // document.getElementById('skip4').onclick=function () { skip("search",4); };
        // document.getElementById('skip5').onclick=function () { skip("search",5); };

        search=document.getElementById('search').value;
        type='search';
        if (search==''){
            alert('请输入搜索信息');
            return;
        }
        $.ajax({
            url:"/hui/TestController/search.do?name="+search,
            type:"get",
            success:function (datas) {
                skipPages(datas.result.length);
                console.log("search"+datas.result);
                $('#imgs').empty();
                $('#imgslow').empty();
                $('#addHr').empty();
                for (var i=0;i<10;i++) {
                    if (userid!=null) {
                        $.ajax({
                            url: "/hui/TestController/checkThumbAndCollect.do?imgid=" + datas.result[i]['id'] + "&userid=" + userid,
                            type: "post",
                            async:false,
                            contentType: false,
                            processData: false,
                            success: function (data) {
                                if (data.resMsg == '未点赞,未收藏')
                                    $('#imgs').append(img1+datas.result[i]['id']+img2+ datas.result[i]['imgname']+img3+ datas.result[i]['title'] + img4 + datas.result[i]['intro'] + img5 + datas.result[i]['id'] + img6 + datas.result[i]['id'] + img7emp + datas.result[i]['id'] + img8 + datas.result[i]['id'] + img9emp + datas.result[i]['thumb'] + img10);
                                else if (data.resMsg == '已点赞,已收藏')
                                    $('#imgs').append(img1+datas.result[i]['id']+img2+ datas.result[i]['imgname']+img3+ datas.result[i]['title'] + img4 + datas.result[i]['intro'] + img5 + datas.result[i]['id'] + img6 + datas.result[i]['id'] + img7 + datas.result[i]['id'] + img8 + datas.result[i]['id'] + img9 + datas.result[i]['thumb'] + img10);
                                else if (data.resMsg == '已点赞,未收藏')
                                    $('#imgs').append(img1+datas.result[i]['id']+img2+ datas.result[i]['imgname']+img3+ datas.result[i]['title'] + img4 + datas.result[i]['intro'] + img5 + datas.result[i]['id'] + img6 + datas.result[i]['id'] + img7emp + datas.result[i]['id'] + img8 + datas.result[i]['id'] + img9 + datas.result[i]['thumb'] + img10);
                                else
                                    $('#imgs').append(img1+datas.result[i]['id']+img2+ datas.result[i]['imgname']+img3+ datas.result[i]['title'] + img4 + datas.result[i]['intro'] + img5 + datas.result[i]['id'] + img6 + datas.result[i]['id'] + img7 + datas.result[i]['id'] + img8 + datas.result[i]['id'] + img9emp + datas.result[i]['thumb'] + img10);
                            },
                            error: function (datas) {
                                console.log(datas);
                            }
                        });
                    }else{
                        $('#imgs').append(img1+datas.result[i]['id']+img2+ datas.result[i]['imgname']+img3+ datas.result[i]['title'] + img4 + datas.result[i]['intro'] + img5 + datas.result[i]['id'] + img6 + datas.result[i]['id'] + img7emp + datas.result[i]['id'] + img8 + datas.result[i]['id'] + img9emp + datas.result[i]['thumb'] + img10);
                    }
                }
            }
        })
    }

    function logout() {
        if (!confirm('确认注销?')){
            return;
        }
        $.ajax({
            url:'/hui/TestController/logout.do',
            headers:{
                accessToken:localStorage.getItem('accessToken')
            },
            success:function (datas) {
                localStorage.removeItem('accessToken');
                sessionStorage.removeItem('id');
                sessionStorage.removeItem('name');
                sessionStorage.removeItem('pic');
                window.location.href='index.html';
            }
        })
    }

    function reg(){
        var name=document.getElementById("regName").value;
        var password=document.getElementById("regPass1").value;
        var password2=document.getElementById("regPass2").value;
        // console.log(name=='');
        if (name==''){
            alert('用户名不能为空');
            return;
        }
        if (password2!=password||password2=='null') {
            alert('两次密码输入不一致');
            return;
        }
        if (password.length<6){
            alert('密码长度必须超过6位');
            return;
        }

        $(document).ready(function() {
            $.ajax({
                url : "hui/TestController/reg.do?name="+name+"&password="+password,//后台请求的数据，用的是PHP
                dataType : "json",//数据格式 
                type : "get",//请求方式
                async : false,//是否异步请求
                success : function(data) {   //如果请求成功，返回数据。
                    if (data.resMsg!="注册成功"){
                        alert(data.resMsg);
                        return;
                    }
                    else {
                        alert("注册成功");
                        window.location.href = "index.html";
                    }
                },
            })
        })
    }

    var img1='<div class="col-sm-6 col-md-4" style="width: 282px;height: 380px;"><div class="thumbnail"><a href="#"><div style="width: 242px;height: 200px;"><img onclick="getimg(';
    var img2=')" src="/';
    var img3='"></div></a><div class="caption"><h3>';
    var img4='</h3><p>';
    var img5='</p><p><a id="collect';
    var img6='" href="#" class="btn btn-default" role="button" onclick="collect(';
    var img7emp=')"><i class="glyphicon glyphicon-star-empty"></i>收藏</a> <a id="thumb';
    var img7=')"><i class="glyphicon glyphicon-star"></i>已收藏</a> <a id="thumb';
    var img8='" href="#" class="btn btn-default" role="button" onclick="thumb(';
    var img9emp=')"><i class="glyphicon glyphicon-heart-empty">点赞</i>';
    var img9=')"><i class="glyphicon glyphicon-heart">已点赞</i>';
    var img10='</a></p></div></div></div>';

    function getimg(imgid){
        sessionStorage.setItem('imgid',imgid);
        $.ajax({
            url:"/hui/TestController/getImgById.do?imgid="+imgid,
            type:"get",
            success:function (data) {
                console.log(data);
                $('#imgs').empty();
                $('#imgslow').empty();
                $('#addHr').empty();
                $.ajax({
                    url:"/hui/TestController/getUserById.do?userid="+data.result['userid'],
                    type:"get",
                    success:function (userdata) {
                        $.ajax({
                            url:'/hui/TestController/checkPurchase.do?userid='+userid+'&imgid='+data.result.id,
                            headers:{
                                accessToken:localStorage.getItem('accessToken')
                            },
                            success:function (datas) {
                                $.ajax({
                                    url:'/hui/TestController/getTags.do?imgid='+imgid,
                                    headers:{
                                        accessToken:localStorage.getItem('accessToken')
                                    },
                                    success:function(tagsData) {
                                        checkToken(tagsData);
                                        sessionStorage.setItem('uploaduser',userdata.result['id']);
                                        var uploadUserId=sessionStorage.getItem('uploaduser');
                                        if (datas.resMsg == '已购买'||uploadUserId==userid)
                                            $('#imgs').append('<div style="text-align: center;"><img src="/' + data.result['imgname'] + '" style="width: 700px;height: 600px"><a href="#" onclick="gotoHimself(' + userdata.result['id'] + ')"><h3>上传人: ' + userdata.result['name'] + '</h3></a><button class="btn btn-info" onclick="backToMain()">返回</button></div><br><div style="text-align: center;"><a href="#"><button class="btn btn-primary btn-lg active">已购买</button></a><a href="/' + data.result['imgname'] + '"download="' + data.result['imgname'] + '"><button class="btn btn-primary btn-lg active">下载图片</button></a></div>');
                                        else
                                            $('#imgs').append('<div style="text-align: center;"><img src="/' + data.result['imgname'] + '" style="width: 700px;height: 600px"><a href="#" onclick="gotoHimself(' + userdata.result['id'] + ')"><h3>上传人: ' + userdata.result['name'] + '</h3></a><button class="btn btn-info" onclick="backToMain()">返回</button></div><br><div style="text-align: center;"><a href="#" onclick="purchase(' + imgid + ')"><button class="btn btn-primary btn-lg active">购买图片(1积分)</button></a><a href="#" onclick="ale()"><button class="btn btn-primary btn-lg active">下载图片</button></a></div>');
                                        $('#imgs').append('<div id="tags" style="text-align: center;"><h3>标签:</h3><br></div>')
                                        for (var i = 0; i < tagsData.result.length; i++) {
                                            if (userid!=uploadUserId)
                                                $('#tags').append('<a href="#" onclick="mySearch2(\'' + tagsData.result[i]['name'] + '\')"><span class="label label-info">' + tagsData.result[i]['name'] + '('+tagsData.result[i]['count']+')</span></a>&nbsp');
                                            else
                                                $('#tags').append('<a href="#" onclick="mySearch2(\'' + tagsData.result[i]['name'] + '\')"><span class="label label-info">' + tagsData.result[i]['name'] + '('+tagsData.result[i]['count']+')</span></a><a href="#"><span class="glyphicon glyphicon-remove" onclick="delTag('+tagsData.result[i]['id']+')"></span></a>&nbsp');
                                        }
                                        getComments();
                                    }
                                })
                            }
                        })
                    },error:function (userdata) {
                        console.log(userdata);
                    }
                })
            },error:function (data) {
                console.log(data);
            }
        })
    }

    function delTag(tagid) {
        if (!confirm('确认删除标签?'))
            return;
        $.ajax({
            url:'/hui/TestController/delTags.do?tagid='+tagid,
            headers:{
                accessToken:localStorage.getItem('accessToken')
            },
            success:function (data) {
                checkToken(data);
                if (data.resMsg!='删除失败'){
                    getimg(sessionStorage.getItem('imgid'));
                }else
                    alert('删除失败');
            }
        })
    }

    function addComments() {
        if (userid==null){
            alert('请在登录后发表评论');
            return;
        }
        var content=$('#content').val();
        var imgid=sessionStorage.getItem('imgid');
        if (content==''){
            alert('内容不能为空');
            return;
        }
        $.ajax({
            url:'/hui/TestController/addComments.do?userid='+userid+'&content='+content+'&imgid='+imgid,
            headers:{
                accessToken:localStorage.getItem('accessToken')
            },
            success:function (data) {
                checkToken(data);
                if (data.resMsg!='添加失败'){
                    getComments();
                }else{
                    alert('发表失败');
                }
            }
        })
    }

    function getComments() {
        $('#rightDiv').empty();
        $('#rightDiv').append('<table id="imgs2" class="table table-hover">' +
            '</table>');
        $('#rightTitle').text('评论列表');
        var imgid = sessionStorage.getItem('imgid');
        $.ajax({
            url: '/hui/TestController/getComments.do?imgid=' + imgid,
            success: function (comments) {
                $('#imgs2').append('<tbody id="rightTable">');
                $('#rightTable').append('<tr> <td>用户名</td><td>评论</td></tr>');
                for (var i = 0; i < comments.result.length; i++) {
                    $('#rightTable').append('<tr><td><a href="#" onclick="gotoHimself('+comments.result[i]['userid']+')"><img src="/'+comments.result[i]['pic']+'" class="img-circle" style="width: 30px;height: 30px">' + comments.result[i]['username'] + '</a></td> ' +
                        '<td>' + comments.result[i]['content'] + '</td><td><a href="#"><span class="glyphicon glyphicon-option-horizontal" onclick="comOption('+comments.result[i]['id']+','+comments.result[i]['userid']+')"></span></a><div id="commentOption'+comments.result[i]['id']+'"></div></td></tr>');
                }
                $('#rightDiv').append('<hr><div class="form-horizontal" style="border-bottom: 1px solid silver">' +
                    '            <div class="form-group">' +
                    '                <label for="pic" class="col-sm-2 control-label">内容</label>' +
                    '                <div class="col-sm-10">' +
                    '                    <input type="text" class="form-control" id="content" name="content">' +
                    '                </div>' +
                    '            </div>' +
                    '            <div class="form-group">' +
                    '                <div class="col-sm-offset-2 col-sm-10">' +
                    '                    <button class="btn btn-default" onclick="addComments()">发表</button>' +
                    '                    <h5>(注:请在登录后发表)</h5>' +
                    '                </div>' +
                    '            </div>' +
                    '        </div>')
            }
        })
    }

    function ale() {
        alert('请购买后再下载');
    }

    function purchase(imgid) {
        $.ajax({
            url:'/hui/TestController/purchaseImg.do?userid='+userid+'&imgid='+imgid,
            headers:{
                accessToken:localStorage.getItem('accessToken')
            },
            success:function (datas) {
                checkToken(datas);
                alert(datas.resMsg);
                getimg(imgid);
                $.ajax({
                    url:'/hui/TestController/getPoints.do?userid='+userid,
                    async:false,
                    headers:{
                        accessToken:localStorage.getItem('accessToken')
                    },
                    success:function (datas) {
                        checkToken(datas);
                        console.log('point:'+datas.result.point);
                        points=datas.result.point;
                        document.getElementById('userpic').innerHTML='积分:'+points+'<img class="img-circle" src="/'+userpic+'" alt="" style="width: 50px;height: 50px">';
                    }
                })
            }
        })
    }

    function getMyImgs() {
        type='my';
        page=1;
        document.getElementById('curpage').innerText=page;


        $.ajax({
            url: "/hui/TestController/getImgByUser.do?userid="+userid,
            type: "post",
            contentType: false,
            processData: false,
            headers:{
                accessToken:localStorage.getItem('accessToken')
            },
            success: function (datas) {
                checkToken(datas);
                $('#imgs').empty();
                $('#imgslow').empty();
                $('#addHr').empty();
                $('#addHr').append('<br><br><br>');

                skipPages(datas.result.length);
                $('#page').show();
                console.log(datas);
                var imgsid='imgs';
                for (var i=0;i<10;i++) {
                    if (userid!=null) {
                        $.ajax({
                            url: "/hui/TestController/checkThumbAndCollect.do?imgid=" + datas.result[i]['id'] + "&userid=" + userid,
                            type: "post",
                            async:false,
                            contentType: false,
                            processData: false,
                            success: function (data) {
                                console.log('ssss:'+data);
                                if (i==5)
                                    imgsid='imgslow';
                                var id=datas.result[i]['id'];
                                if (data.resMsg == '未点赞,未收藏')
                                    $('#'+imgsid).append("<div id='img"+id+"'>"+img1+datas.result[i]['id']+img2+ datas.result[i]['imgname']+img3+ datas.result[i]['title'] + img4 + datas.result[i]['intro'] + img5 + datas.result[i]['id'] + img6 + datas.result[i]['id'] + img7emp + datas.result[i]['id'] + img8 + datas.result[i]['id'] + img9emp + datas.result[i]['thumb'] +'</a><hr><button class="btn btn-default" onclick="updateImg('+id+')">修改</button><button class="btn btn-default" onclick="deleteImgById('+id+')">删除</button><button class="btn btn-default" onclick="addTags('+id+')">添加标签</button>'+ '</p></div></div></div></div>');
                                else if (data.resMsg == '已点赞,已收藏')
                                    $('#'+imgsid).append("<div id='img"+id+"'>"+img1+datas.result[i]['id']+img2+ datas.result[i]['imgname']+img3+ datas.result[i]['title'] + img4 + datas.result[i]['intro'] + img5 + datas.result[i]['id'] + img6 + datas.result[i]['id'] + img7 + datas.result[i]['id'] + img8 + datas.result[i]['id'] + img9 + datas.result[i]['thumb'] +'</a><hr><button class="btn btn-default" onclick="updateImg('+id+')">修改</button><button class="btn btn-default" onclick="deleteImgById('+id+')">删除</button><button class="btn btn-default" onclick="addTags('+id+')">添加标签</button>'+ '</p></div></div></div></div>');
                                else if (data.resMsg == '已点赞,未收藏')
                                    $('#'+imgsid).append("<div id='img"+id+"'>"+img1+datas.result[i]['id']+img2+ datas.result[i]['imgname']+img3+ datas.result[i]['title'] + img4 + datas.result[i]['intro'] + img5 + datas.result[i]['id'] + img6 + datas.result[i]['id'] + img7emp + datas.result[i]['id'] + img8 + datas.result[i]['id'] + img9 + datas.result[i]['thumb'] +'</a><hr><button class="btn btn-default" onclick="updateImg('+id+')">修改</button><button class="btn btn-default" onclick="deleteImgById('+id+')">删除</button><button class="btn btn-default" onclick="addTags('+id+')">添加标签</button>'+ '</p></div></div></div></div>');
                                else
                                    $('#'+imgsid).append("<div id='img"+id+"'>"+img1+datas.result[i]['id']+img2+ datas.result[i]['imgname']+img3+ datas.result[i]['title'] + img4 + datas.result[i]['intro'] + img5 + datas.result[i]['id'] + img6 + datas.result[i]['id'] + img7 + datas.result[i]['id'] + img8 + datas.result[i]['id'] + img9emp + datas.result[i]['thumb'] +'</a><hr><button class="btn btn-default" onclick="updateImg('+id+')">修改</button><button class="btn btn-default" onclick="deleteImgById('+id+')">删除</button><button class="btn btn-default" onclick="addTags('+id+')">添加标签</button>'+ '</p></div></div></div></div>');
                            },
                            error: function (datas) {
                                console.log(datas);
                            }
                        });
                    }else{
                        $('#imgs').append(img1+datas.result[i]['id']+img2+ datas.result[i]['imgname']+img3+ datas.result[i]['title'] + img4 + datas.result[i]['intro'] + img5 + datas.result[i]['id'] + img6 + datas.result[i]['id'] + img7emp + datas.result[i]['id'] + img8 + datas.result[i]['id'] + img9emp + datas.result[i]['thumb'] + img10);
                    }
                }
            },
            error: function (datas) {
                console.log(datas);
            }
        });
    }

    var upimg1='<div class="col-sm-6 col-md-4" style="width: 282px;height: 380px;"><div class="thumbnail"><a href="#"><div style="width: 242px;height: 200px;"><img onclick="getimg(';
    var upimg2=')" src="/';
    var upimg3='"></div></a><input id="newtitle" type="text" class="form-control" value="';
    var upimg4='"><input id="newintro" type="text" class="form-control" value="';
    var upimg5='"><select class="form-control" id="imgtypes"></select>';
    function updateImg(imgid) {
        $('#img'+imgid).empty();
        $.ajax({
            url:'/hui/TestController/getImgById.do?imgid='+imgid,
            headers:{
                accessToken:localStorage.getItem('accessToken')
            },
            success:function (datas) {
                checkToken(datas)
                $.ajax({
                    url:'/admin/getTypes.do',
                    type:'get',
                    contentType: false,
                    processData: false,
                    success:function (datat) {
                        // console.log('获取类型下拉'+datas);
                        // console.log('获取类型下拉'+datas.result);
                        $('#img'+imgid).append(upimg1+datas.result.id+upimg2+ datas.result.imgname+upimg3+ datas.result.title+ upimg4 + datas.result.intro + upimg5 +'<button class="btn btn-default" onclick="updateImg2('+imgid+')">确认</button>'+ '</p></div></div></div>')
                        for (var i=0;i<datat.result.length;i++) {
                            if (datat.result[i]['id']==datas.result.typeid) {
                                $('#imgtypes').append('<option value="' + datat.result[i]['id'] + '" selected="selected">' + datat.result[i]['name'] + '</option>');
                            }
                            else{
                                $('#imgtypes').append('<option value="' + datat.result[i]['id'] + '">' + datat.result[i]['name'] + '</option>');
                            }
                        }
                    }
                })
            }
        })
    }

    function updateImg2(imgid) {
        var newtitle=$('#newtitle').val();
        var newintro=$('#newintro').val();
        var newtype=$('#imgtypes').val();
        $.ajax({
            url:'/hui/TestController/updateImg.do?id='+imgid+'&title='+newtitle+'&intro='+newintro+'&typeid='+newtype,
            headers:{
                accessToken:localStorage.getItem('accessToken')
            },
            success:function (data) {
                checkToken(data)
                if (data.resMsg=='修改成功'){
                    alert('修改成功');
                    getMyImgs();
                }else{
                    alert(data.resMsg);
                }
            }
        })
    }

var staticId=0;
    function addTags(id) {
        $('#addTagsModal').show();
        staticId=id;
        $("#addTagsModal").modal({
            backdrop: "static",
            keyboard: false,
        });
    }
    function addTags2(id) {
        var tags=$('#tags').val();
        $.ajax({
            url:'/hui/TestController/addTags.do?imgid='+id+'&tags='+tags,
            headers:{
                accessToken:localStorage.getItem('accessToken')
            },
            success:function (data) {
                checkToken(data);
                if (data.resMsg!='添加失败'){
                    alert('添加成功');
                    $('#addTagsModal').hide();
                }else{
                    alert('添加失败');
                }
            }
        })
    }
    function hide() {
        $('#addTagsModal').hide();
    }

    function deleteImgById(imgid) {
        console.log('imgid:'+imgid);
        if (!confirm('确认删除?')) {
            return;
        }
        $.ajax({
            url:'/admin/deleteImgById.do?imgid='+imgid,
            headers:{
                accessToken:localStorage.getItem('accessToken')
            },
            type:'get',
            success:function (datas) {
                checkToken(datas);
                if (datas.resMsg!='删除失败')
                    alert('删除成功');
                else
                    alert('删除失败');
                getMyImgs()
            },error:function (datas) {
                alert('删除失败2');
            }
        })
    }
    function getMyFans() {
        type='fans';
        page=1;
        document.getElementById('curpage').innerText=page;
        $('#page').show();
        $('#imgs').empty();
        $('#imgslow').empty();
        $('#addHr').empty();
        $('#imgs').append('<tr> <td>编号</td> <td>用户名</td> <td>用户头像</td> <td>操作</td> </tr>');
        $.ajax({
            url:'/hui/TestController/getFans.do?userid='+userid,
            headers:{
                accessToken:localStorage.getItem('accessToken')
            },
            dataType:'json',
            success:function (datas) {
                checkToken(datas);
                skipPages(datas.result.length);

                console.log('fans:'+datas);
                for (var i =0;i<10;i++) {
                    var n=parseInt(i)+1;
                    $('#imgs').append('<tr><td>' + n + '</td><td>' + datas.result[i]['name'] + '</td><td><img class="img img-circle" src="/' + datas.result[i]['pic'] + '" alt="" style="width: 50px;height: 50px"></td><td><a href="#" onclick="attention(' + datas.result[i]['id'] + ')">关注</a>|<a href="#" onclick="gotoHimself(' + datas.result[i]['id'] + ')">他的主页</a></td></tr>');
                }
                }
        })
    }

    function getMyAts() {
        type='ats';
        page=1;
        document.getElementById('curpage').innerText=page;
        $('#page').show();
        $('#imgs').empty();
        $('#imgslow').empty();
        $('#addHr').empty();
        $('#imgs').append('<tr> <td>编号</td> <td>用户名</td> <td>用户头像</td> <td>操作</td> </tr>');
        $.ajax({
            url:'/hui/TestController/getAt.do?userid='+userid,
            dataType:'json',
            headers:{
                accessToken:localStorage.getItem('accessToken')
            },
            success:function (datas) {
                checkToken(datas);
                skipPages(datas.result.length);

                console.log('ats:'+datas);
                for (var i =0;i<10;i++) {
                    var n=parseInt(i)+1;
                    $('#imgs').append('<tr><td>' + n + '</td><td>' + datas.result[i]['name'] + '</td><td><img class="img img-circle" src="/' + datas.result[i]['pic'] + '" alt="" style="width: 50px;height: 50px"></td><td><a href="#" onclick="unattention(' + datas.result[i]['id'] + ')">取消关注</a>|<a href="#" onclick="gotoHimself(' + datas.result[i]['id'] + ')">他的主页</a></td></tr>');
                }
            }
        })
    }

    function gotoHimself(goid) {
        sessionStorage.setItem('goid',goid);
        window.location.href='himself.html';
    }
    function attention(atid) {
        $.ajax({
            url:'/hui/TestController/attention.do?atid='+atid+'&fanid='+userid,
            headers:{
                accessToken:localStorage.getItem('accessToken')
            },
            dataType:'json',
            success:function (datas) {
                checkToken(datas);
                if (datas.resMsg!='关注失败'&&datas.resMsg!='已关注过')
                    alert('关注成功');
                else if (datas.resMsg=='已关注过')
                    alert('已关注过，不能重复关注');
                else
                    alert('关注失败');
                skip(type,page);
            }
        })
    }

    function unattention(atid){
        $.ajax({
            url:'/hui/TestController/unattention.do?atid='+atid+'&fanid='+userid,
            headers:{
                accessToken:localStorage.getItem('accessToken')
            },
            dataType:'json',
            success:function (datas) {
                checkToken(datas);
                if (datas.resMsg!='取消关注失败')
                    alert('取消关注成功');
                else
                    alert('取消关注失败');
                skip(type,page);
            }
        })
    }
    function getMyCollects() {
        type='collect';
        page=1;
        document.getElementById('curpage').innerText=page;
        $.ajax({
            url: "/hui/TestController/getImgsOnCollect.do",
            headers:{
                accessToken:localStorage.getItem('accessToken')
            },
            type: "post",
            contentType: false,
            processData: false,
            success: function (datas) {
                checkToken(datas);
                $('#imgs').empty();
                $('#imgslow').empty();
                $('#addHr').empty();
                skipPages(datas.result.length);

                $('#page').show();
                console.log(datas);
                for (var i=0;i<10;i++) {
                    console.log('user:'+userid);
                    if (userid!=null) {
                        $.ajax({
                            url: "/hui/TestController/checkThumbAndCollect.do?imgid=" + datas.result[i]['id'] + "&userid=" + userid,
                            type: "post",
                            async:false,
                            contentType: false,
                            processData: false,
                            success: function (data) {
                                console.log('ssss:'+data);
                                if (data.resMsg == '未点赞,未收藏')
                                    $('#imgs').append(img1+datas.result[i]['id']+img2+ datas.result[i]['imgname']+img3+ datas.result[i]['title'] + img4 + datas.result[i]['intro'] + img5 + datas.result[i]['id'] + img6 + datas.result[i]['id'] + img7emp + datas.result[i]['id'] + img8 + datas.result[i]['id'] + img9emp + datas.result[i]['thumb'] + img10);
                                else if (data.resMsg == '已点赞,已收藏')
                                    $('#imgs').append(img1+datas.result[i]['id']+img2+ datas.result[i]['imgname']+img3+ datas.result[i]['title'] + img4 + datas.result[i]['intro'] + img5 + datas.result[i]['id'] + img6 + datas.result[i]['id'] + img7 + datas.result[i]['id'] + img8 + datas.result[i]['id'] + img9 + datas.result[i]['thumb'] + img10);
                                else if (data.resMsg == '已点赞,未收藏')
                                    $('#imgs').append(img1+datas.result[i]['id']+img2+ datas.result[i]['imgname']+img3+ datas.result[i]['title'] + img4 + datas.result[i]['intro'] + img5 + datas.result[i]['id'] + img6 + datas.result[i]['id'] + img7emp + datas.result[i]['id'] + img8 + datas.result[i]['id'] + img9 + datas.result[i]['thumb'] + img10);
                                else
                                    $('#imgs').append(img1+datas.result[i]['id']+img2+ datas.result[i]['imgname']+img3+ datas.result[i]['title'] + img4 + datas.result[i]['intro'] + img5 + datas.result[i]['id'] + img6 + datas.result[i]['id'] + img7 + datas.result[i]['id'] + img8 + datas.result[i]['id'] + img9emp + datas.result[i]['thumb'] + img10);
                            },
                            error: function (datas) {
                                console.log(datas);
                            }
                        });
                    }else{
                        $('#imgs').append(img1+datas.result[i]['id']+img2+ datas.result[i]['imgname']+img3+ datas.result[i]['title'] + img4 + datas.result[i]['intro'] + img5 + datas.result[i]['id'] + img6 + datas.result[i]['id'] + img7emp + datas.result[i]['id'] + img8 + datas.result[i]['id'] + img9emp + datas.result[i]['thumb'] + img10);
                    }
                }
            },
            error: function (datas) {
                console.log(datas);
            }
        });
    }

    function getMyPurchase() {
        console.log(localStorage.getItem('accessToken'));
        type='purchase';
        page=1;
        document.getElementById('curpage').innerText=page;
        $.ajax({
            url: "/hui/TestController/getImgPurchase.do?userid="+userid,
            headers:{
                accessToken:localStorage.getItem('accessToken')
            },
            success: function (datas) {
                checkToken(datas);
                $('#imgs').empty();
                $('#imgslow').empty();
                $('#addHr').empty();
                skipPages(datas.result.length);

                $('#page').show();
                console.log(datas);
                for (var i=0;i<10;i++) {
                    console.log('user:'+userid);
                    if (userid!=null) {
                        $.ajax({
                            url: "/hui/TestController/checkThumbAndCollect.do?imgid=" + datas.result[i]['id'] + "&userid=" + userid,
                            type: "post",
                            async:false,
                            contentType: false,
                            processData: false,
                            success: function (data) {
                                console.log('ssss:'+data);
                                if (data.resMsg == '未点赞,未收藏')
                                    $('#imgs').append(img1+datas.result[i]['id']+img2+ datas.result[i]['imgname']+img3+ datas.result[i]['title'] + img4 + datas.result[i]['intro'] + img5 + datas.result[i]['id'] + img6 + datas.result[i]['id'] + img7emp + datas.result[i]['id'] + img8 + datas.result[i]['id'] + img9emp + datas.result[i]['thumb'] + img10);
                                else if (data.resMsg == '已点赞,已收藏')
                                    $('#imgs').append(img1+datas.result[i]['id']+img2+ datas.result[i]['imgname']+img3+ datas.result[i]['title'] + img4 + datas.result[i]['intro'] + img5 + datas.result[i]['id'] + img6 + datas.result[i]['id'] + img7 + datas.result[i]['id'] + img8 + datas.result[i]['id'] + img9 + datas.result[i]['thumb'] + img10);
                                else if (data.resMsg == '已点赞,未收藏')
                                    $('#imgs').append(img1+datas.result[i]['id']+img2+ datas.result[i]['imgname']+img3+ datas.result[i]['title'] + img4 + datas.result[i]['intro'] + img5 + datas.result[i]['id'] + img6 + datas.result[i]['id'] + img7emp + datas.result[i]['id'] + img8 + datas.result[i]['id'] + img9 + datas.result[i]['thumb'] + img10);
                                else
                                    $('#imgs').append(img1+datas.result[i]['id']+img2+ datas.result[i]['imgname']+img3+ datas.result[i]['title'] + img4 + datas.result[i]['intro'] + img5 + datas.result[i]['id'] + img6 + datas.result[i]['id'] + img7 + datas.result[i]['id'] + img8 + datas.result[i]['id'] + img9emp + datas.result[i]['thumb'] + img10);
                            },
                            error: function (datas) {
                                console.log(datas);
                            }
                        });
                    }else{
                        $('#imgs').append(img1+datas.result[i]['id']+img2+ datas.result[i]['imgname']+img3+ datas.result[i]['title'] + img4 + datas.result[i]['intro'] + img5 + datas.result[i]['id'] + img6 + datas.result[i]['id'] + img7emp + datas.result[i]['id'] + img8 + datas.result[i]['id'] + img9emp + datas.result[i]['thumb'] + img10);
                    }
                }
            },
            error: function (datas) {
                console.log(datas);
            }
        });
    }

    function skip(type,flag) {
        $('#rightTitle').empty();
        $('#rightDiv').empty();
        if (flag==-1)
            page=page-1;
        else if (flag==0)
            page=page+1;
        else
            page=flag;
        if (page<=0)
            page=1;
        if (page>pages)
            page=pages;
        document.getElementById('curpage').innerText=page;
        var imgsid='imgs';
        $('#toPageNum').val(page);
        if (type=='my'){
            $.ajax({
                url: "/hui/TestController/getImgByUser.do?userid="+userid,
                type: "post",
                contentType: false,
                processData: false,
                headers:{
                    accessToken:localStorage.getItem('accessToken')
                },
                success: function (datas) {
                    checkToken(datas);
                    console.log('my'+datas);
                    $('#imgs').empty();
                    $('#imgslow').empty();
                    $('#addHr').empty();
                    $('#addHr').append('<br><br><br>');
                    for (var i=(page-1)*10;i<page*10;i++) {
                        if (userid!=null) {
                            $.ajax({
                                url: "/hui/TestController/checkThumbAndCollect.do?imgid=" + datas.result[i]['id'] + "&userid=" + userid,
                                type: "post",
                                async:false,
                                contentType: false,
                                processData: false,
                                success: function (data) {
                                    if (i==(page-1)*10)
                                        imgsid='imgs';
                                    if (i==(page-1)*10+5)
                                        imgsid='imgslow';
                                    var id=datas.result[i]['id'];
                                    if (data.resMsg == '未点赞,未收藏')
                                        $('#'+imgsid).append("<div id='img"+id+"'>"+img1+datas.result[i]['id']+img2+ datas.result[i]['imgname']+img3+ datas.result[i]['title'] + img4 + datas.result[i]['intro'] + img5 + datas.result[i]['id'] + img6 + datas.result[i]['id'] + img7emp + datas.result[i]['id'] + img8 + datas.result[i]['id'] + img9emp + datas.result[i]['thumb'] +'</a><hr><button class="btn btn-default" onclick="updateImg('+id+')">修改</button><button class="btn btn-default" onclick="deleteImgById('+id+')">删除</button><button class="btn btn-default" onclick="addTags('+id+')">添加标签</button>'+ '</p></div></div></div></div>');
                                    else if (data.resMsg == '已点赞,已收藏')
                                        $('#'+imgsid).append("<div id='img"+id+"'>"+img1+datas.result[i]['id']+img2+ datas.result[i]['imgname']+img3+ datas.result[i]['title'] + img4 + datas.result[i]['intro'] + img5 + datas.result[i]['id'] + img6 + datas.result[i]['id'] + img7 + datas.result[i]['id'] + img8 + datas.result[i]['id'] + img9 + datas.result[i]['thumb'] +'</a><hr><button class="btn btn-default" onclick="updateImg('+id+')">修改</button><button class="btn btn-default" onclick="deleteImgById('+id+')">删除</button><button class="btn btn-default" onclick="addTags('+id+')">添加标签</button>'+ '</p></div></div></div></div>');
                                    else if (data.resMsg == '已点赞,未收藏')
                                        $('#'+imgsid).append("<div id='img"+id+"'>"+img1+datas.result[i]['id']+img2+ datas.result[i]['imgname']+img3+ datas.result[i]['title'] + img4 + datas.result[i]['intro'] + img5 + datas.result[i]['id'] + img6 + datas.result[i]['id'] + img7emp + datas.result[i]['id'] + img8 + datas.result[i]['id'] + img9 + datas.result[i]['thumb'] +'</a><hr><button class="btn btn-default" onclick="updateImg('+id+')">修改</button><button class="btn btn-default" onclick="deleteImgById('+id+')">删除</button><button class="btn btn-default" onclick="addTags('+id+')">添加标签</button>'+ '</p></div></div></div></div>');
                                    else
                                        $('#'+imgsid).append("<div id='img"+id+"'>"+img1+datas.result[i]['id']+img2+ datas.result[i]['imgname']+img3+ datas.result[i]['title'] + img4 + datas.result[i]['intro'] + img5 + datas.result[i]['id'] + img6 + datas.result[i]['id'] + img7 + datas.result[i]['id'] + img8 + datas.result[i]['id'] + img9emp + datas.result[i]['thumb'] +'</a><hr><button class="btn btn-default" onclick="updateImg('+id+')">修改</button><button class="btn btn-default" onclick="deleteImgById('+id+')">删除</button><button class="btn btn-default" onclick="addTags('+id+')">添加标签</button>'+ '</p></div></div></div></div>');
                                },
                                error: function (datas) {
                                    console.log(datas);
                                }
                            });
                        }else{
                            $('#imgs').append(img1+datas.result[i]['id']+img2+ datas.result[i]['imgname']+img3+ datas.result[i]['title'] + img4 + datas.result[i]['intro'] + img5 + datas.result[i]['id'] + img6 + datas.result[i]['id'] + img7emp + datas.result[i]['id'] + img8 + datas.result[i]['id'] + img9emp + datas.result[i]['thumb'] + img10);
                        }
                    }
                },
                error: function (datas) {
                    console.log(datas);
                }
            });
        }
        if (type=='collect'){
            $.ajax({
                url: "/hui/TestController/getImgsOnCollect.do",
                headers:{
                    accessToken:localStorage.getItem('accessToken')
                },
                type: "post",
                contentType: false,
                processData: false,
                success: function (datas) {
                    checkToken(datas);
                    console.log(datas);
                    $('#imgs').empty();
                    $('#imgslow').empty();
                    $('#addHr').empty();
                    for (var i=(page-1)*10;i<page*10;i++) {
                        if (userid!=null) {
                            $.ajax({
                                url: "/hui/TestController/checkThumbAndCollect.do?imgid=" + datas.result[i]['id'] + "&userid=" + userid,
                                type: "post",
                                async:false,
                                contentType: false,
                                processData: false,
                                success: function (data) {
                                    if (data.resMsg == '未点赞,未收藏')
                                        $('#imgs').append(img1+datas.result[i]['id']+img2+ datas.result[i]['imgname']+img3+ datas.result[i]['title'] + img4 + datas.result[i]['intro'] + img5 + datas.result[i]['id'] + img6 + datas.result[i]['id'] + img7emp + datas.result[i]['id'] + img8 + datas.result[i]['id'] + img9emp + datas.result[i]['thumb'] + img10);
                                    else if (data.resMsg == '已点赞,已收藏')
                                        $('#imgs').append(img1+datas.result[i]['id']+img2+ datas.result[i]['imgname']+img3+ datas.result[i]['title'] + img4 + datas.result[i]['intro'] + img5 + datas.result[i]['id'] + img6 + datas.result[i]['id'] + img7 + datas.result[i]['id'] + img8 + datas.result[i]['id'] + img9 + datas.result[i]['thumb'] + img10);
                                    else if (data.resMsg == '已点赞,未收藏')
                                        $('#imgs').append(img1+datas.result[i]['id']+img2+ datas.result[i]['imgname']+img3+ datas.result[i]['title'] + img4 + datas.result[i]['intro'] + img5 + datas.result[i]['id'] + img6 + datas.result[i]['id'] + img7emp + datas.result[i]['id'] + img8 + datas.result[i]['id'] + img9 + datas.result[i]['thumb'] + img10);
                                    else
                                        $('#imgs').append(img1+datas.result[i]['id']+img2+ datas.result[i]['imgname']+img3+ datas.result[i]['title'] + img4 + datas.result[i]['intro'] + img5 + datas.result[i]['id'] + img6 + datas.result[i]['id'] + img7 + datas.result[i]['id'] + img8 + datas.result[i]['id'] + img9emp + datas.result[i]['thumb'] + img10);
                                },
                                error: function (datas) {
                                    console.log(datas);
                                }
                            });
                        }else{
                            $('#imgs').append(img1+datas.result[i]['id']+img2+ datas.result[i]['imgname']+img3+ datas.result[i]['title'] + img4 + datas.result[i]['intro'] + img5 + datas.result[i]['id'] + img6 + datas.result[i]['id'] + img7emp + datas.result[i]['id'] + img8 + datas.result[i]['id'] + img9emp + datas.result[i]['thumb'] + img10);
                        }
                    }
                },
                error: function (datas) {
                    console.log(datas);
                }
            });
        }
        if (type=='search'){
            $.ajax({
                url:"/hui/TestController/search.do?name="+search,
                type:"get",
                success:function (datas) {
                    console.log("search"+datas.result);
                    $('#imgs').empty();
                    $('#imgslow').empty();
                    $('#addHr').empty();
                    for (var i=(page-1)*10;i<page*10;i++) {
                        if (userid!=null) {
                            $.ajax({
                                url: "/hui/TestController/checkThumbAndCollect.do?imgid=" + datas.result[i]['id'] + "&userid=" + userid,
                                type: "post",
                                async:false,
                                contentType: false,
                                processData: false,
                                success: function (data) {
                                    if (data.resMsg == '未点赞,未收藏')
                                        $('#imgs').append(img1+datas.result[i]['id']+img2+ datas.result[i]['imgname']+img3+ datas.result[i]['title'] + img4 + datas.result[i]['intro'] + img5 + datas.result[i]['id'] + img6 + datas.result[i]['id'] + img7emp + datas.result[i]['id'] + img8 + datas.result[i]['id'] + img9emp + datas.result[i]['thumb'] + img10);
                                    else if (data.resMsg == '已点赞,已收藏')
                                        $('#imgs').append(img1+datas.result[i]['id']+img2+ datas.result[i]['imgname']+img3+ datas.result[i]['title'] + img4 + datas.result[i]['intro'] + img5 + datas.result[i]['id'] + img6 + datas.result[i]['id'] + img7 + datas.result[i]['id'] + img8 + datas.result[i]['id'] + img9 + datas.result[i]['thumb'] + img10);
                                    else if (data.resMsg == '已点赞,未收藏')
                                        $('#imgs').append(img1+datas.result[i]['id']+img2+ datas.result[i]['imgname']+img3+ datas.result[i]['title'] + img4 + datas.result[i]['intro'] + img5 + datas.result[i]['id'] + img6 + datas.result[i]['id'] + img7emp + datas.result[i]['id'] + img8 + datas.result[i]['id'] + img9 + datas.result[i]['thumb'] + img10);
                                    else
                                        $('#imgs').append(img1+datas.result[i]['id']+img2+ datas.result[i]['imgname']+img3+ datas.result[i]['title'] + img4 + datas.result[i]['intro'] + img5 + datas.result[i]['id'] + img6 + datas.result[i]['id'] + img7 + datas.result[i]['id'] + img8 + datas.result[i]['id'] + img9emp + datas.result[i]['thumb'] + img10);
                                },
                                error: function (datas) {
                                    console.log(datas);
                                }
                            });
                        }else{
                            $('#imgs').append(img1+datas.result[i]['id']+img2+ datas.result[i]['imgname']+img3+ datas.result[i]['title'] + img4 + datas.result[i]['intro'] + img5 + datas.result[i]['id'] + img6 + datas.result[i]['id'] + img7emp + datas.result[i]['id'] + img8 + datas.result[i]['id'] + img9emp + datas.result[i]['thumb'] + img10);
                        }
                    }
                }
            })
        }
        if (type=='fans'){
            $('#imgs').empty();
            $('#imgslow').empty();
            $('#addHr').empty();
            $('#imgs').append('<tr> <td>编号</td> <td>用户名</td> <td>用户头像</td> <td>操作</td> </tr>');
            $.ajax({
                url:'/hui/TestController/getFans.do?userid='+userid,
                headers:{
                    accessToken:localStorage.getItem('accessToken')
                },
                dataType:'json',
                success:function (datas) {
                    checkToken(datas);
                    console.log('fans:'+datas);
                    for (var i=(page-1)*10;i<page*10;i++) {
                        var n=parseInt(i)+1;
                        $('#imgs').append('<tr><td>' + n + '</td><td>' + datas.result[i]['name'] + '</td><td><img class="img img-circle" src="/' + datas.result[i]['pic'] + '" alt="" style="width: 50px;height: 50px"></td><td><a href="#" onclick="attention(' + datas.result[i]['id'] + ')">关注</a>|<a href="#" onclick="gotoHimslef(' + datas.result[i]['id'] + ')">他的主页</a></td></tr>');
                    }
                    }
            })
        }
        if (type=='ats'){
            $('#imgs').empty();
            $('#imgslow').empty();
            $('#addHr').empty();
            $('#imgs').append('<tr> <td>编号</td> <td>用户名</td> <td>用户头像</td> <td>操作</td> </tr>');
            $.ajax({
                url:'/hui/TestController/getAt.do?userid='+userid,
                headers:{
                    accessToken:localStorage.getItem('accessToken')
                },
                dataType:'json',
                success:function (datas) {
                    checkToken(datas);
                    console.log('ats:'+datas);
                    for (var i=(page-1)*10;i<page*10;i++) {
                        var n=parseInt(i)+1;
                        $('#imgs').append('<tr><td>' + n + '</td><td>' + datas.result[i]['name'] + '</td><td><img class="img img-circle" src="/' + datas.result[i]['pic'] + '" alt="" style="width: 50px;height: 50px"></td><td><a href="#" onclick="unattention(' + datas.result[i]['id'] + ')">取消关注</a>|<a href="#" onclick="gotoHimslef(' + datas.result[i]['id'] + ')">他的主页</a></td></tr>');
                    }
                }
            })
        }
        if (type=='purchase'){
            $.ajax({
                url: "/hui/TestController/getImgPurchase.do?userid="+userid,
                headers:{
                    accessToken:localStorage.getItem('accessToken')
                },
                success: function (datas) {
                    checkToken(datas);
                    $('#imgs').empty();
                    $('#imgslow').empty();
                    $('#addHr').empty();
                    $('#page').show();
                    console.log(datas);
                    for (var i=(page-1)*10;i<page*10;i++) {
                        console.log(datas.result[i]);
                        if (userid!=null) {
                            $.ajax({
                                url: "/hui/TestController/checkThumbAndCollect.do?imgid=" + datas.result[i]['id'] + "&userid=" + userid,
                                type: "post",
                                async:false,
                                contentType: false,
                                processData: false,
                                success: function (data) {
                                    console.log('ssss:'+data);
                                    if (data.resMsg == '未点赞,未收藏')
                                        $('#imgs').append(img1+datas.result[i]['id']+img2+ datas.result[i]['imgname']+img3+ datas.result[i]['title'] + img4 + datas.result[i]['intro'] + img5 + datas.result[i]['id'] + img6 + datas.result[i]['id'] + img7emp + datas.result[i]['id'] + img8 + datas.result[i]['id'] + img9emp + datas.result[i]['thumb'] + img10);
                                    else if (data.resMsg == '已点赞,已收藏')
                                        $('#imgs').append(img1+datas.result[i]['id']+img2+ datas.result[i]['imgname']+img3+ datas.result[i]['title'] + img4 + datas.result[i]['intro'] + img5 + datas.result[i]['id'] + img6 + datas.result[i]['id'] + img7 + datas.result[i]['id'] + img8 + datas.result[i]['id'] + img9 + datas.result[i]['thumb'] + img10);
                                    else if (data.resMsg == '已点赞,未收藏')
                                        $('#imgs').append(img1+datas.result[i]['id']+img2+ datas.result[i]['imgname']+img3+ datas.result[i]['title'] + img4 + datas.result[i]['intro'] + img5 + datas.result[i]['id'] + img6 + datas.result[i]['id'] + img7emp + datas.result[i]['id'] + img8 + datas.result[i]['id'] + img9 + datas.result[i]['thumb'] + img10);
                                    else
                                        $('#imgs').append(img1+datas.result[i]['id']+img2+ datas.result[i]['imgname']+img3+ datas.result[i]['title'] + img4 + datas.result[i]['intro'] + img5 + datas.result[i]['id'] + img6 + datas.result[i]['id'] + img7 + datas.result[i]['id'] + img8 + datas.result[i]['id'] + img9emp + datas.result[i]['thumb'] + img10);
                                },
                                error: function (datas) {
                                    console.log(datas);
                                }
                            });
                        }else{
                            $('#imgs').append(img1+datas.result[i]['id']+img2+ datas.result[i]['imgname']+img3+ datas.result[i]['title'] + img4 + datas.result[i]['intro'] + img5 + datas.result[i]['id'] + img6 + datas.result[i]['id'] + img7emp + datas.result[i]['id'] + img8 + datas.result[i]['id'] + img9emp + datas.result[i]['thumb'] + img10);
                        }
                    }
                },
                error: function (datas) {
                    console.log(datas);
                }
            });
        }
    }

    function thumb(id) {
        if (userid==null){
            alert('请在登录后点赞');
            return;
        }
        $.ajax({
            url: "/hui/TestController/thumb.do?imgid="+id+"&userid="+userid,
            headers:{
                accessToken:localStorage.getItem('accessToken')
            },
            type: "post",
            success: function (data) {
                checkToken(data);
                console.log(data);
                skip(type,page);
            },
            error: function (data) {
                console.log(data);
            }
        });
    }
    function collect(imgid){
        if (userid==null){
            alert('请在登录后收藏');
            return;
        }
        $.ajax({
            url: "/hui/TestController/collect.do?imgid="+imgid+"&userid="+userid,
            headers:{
                accessToken:localStorage.getItem('accessToken')
            },
            type: "post",
            success: function (data) {
                checkToken(data);
                console.log(data);
                skip(type,page);
            },
            error: function (data) {
                console.log(data);
            }
        });
    }
    function backToMain(){
        skip(type,page);
    }

    function updateUser() {
        $('#imgs').empty();
        $('#imgslow').empty();
        $('#addHr').empty();
        $('#page').hide();
        $(document).keypress(function(e) {
            if (e.keyCode == 13) {
                // 触发需要调用的方法
                update();
            }
        })
        $('#imgs').append('<div class="form-horizontal" id="updateUser"> <div class="form-group"> <label for="pic" class="col-sm-2 control-label">头像</label> <div class="col-sm-10"> <input type="file" style="width: 25%;" class="form-control" id="pic" name="pic"> </div> </div> <div class="form-group"> <label for="pic" class="col-sm-2 control-label">用户名</label> <div class="col-sm-10"> <input type="text" style="width: 25%;" class="form-control" id="user" name="user"> </div> </div> <div class="form-group" style="text-align: left"> <div class="col-sm-offset-2 col-sm-10"> <button type="submit" class="btn btn-default" onclick="update()">修改</button> </div> </div> </div>');
    }

    function updatePassword() {
        $('#imgs').empty();
        $('#imgslow').empty();
        $('#addHr').empty();
        $('#page').hide();
        $(document).keypress(function(e) {
            if (e.keyCode == 13) {
                // 触发需要调用的方法
                update2();
            }
        })
        $('#imgs').append('<div class="form-horizontal" id="updatePass">' +
            ' <div class="form-group">' +
            ' <label for="pass" class="col-sm-2 control-label">原密码</label>' +
            ' <div class="col-sm-10">' +
            ' <input type="text" style="width: 25%;" class="form-control" id="pass" name="pass">' +
            ' </div>' +
            ' </div>' +
            '<div class="form-group" style="text-align: left">' +
            ' <div class="col-sm-offset-2 col-sm-10" id="erPass0">' +
            '</div></div> <div class="form-group">' +
            ' <label for="newpass" class="col-sm-2 control-label">新密码</label>' +
            ' <div class="col-sm-10"> ' +
            '<input type="password" style="width: 25%;" class="form-control" id="newpass" name="newpass">' +
            ' </div> </div><div class="form-group" style="text-align: left">' +
            ' <div class="col-sm-offset-2 col-sm-10" id="erPass1">' +
            '</div></div><div class="form-group">' +
            ' <label for="newpass2" class="col-sm-2 control-label">确认密码</label>' +
            ' <div class="col-sm-10">' +
            ' <input type="password" style="width: 25%;" class="form-control" id="newpass2" name="newpass2">' +
            ' </div> </div><div class="form-group" style="text-align: left">' +
            ' <div class="col-sm-offset-2 col-sm-10" id="erPass2">' +
            '</div></div> <div class="form-group" style="text-align: left">' +
            ' <div class="col-sm-offset-2 col-sm-10">' +
            ' <button type="submit" class="btn btn-default" onclick="update2()">修改</button>' +
            ' </div>' +
            ' </div>' +
            ' </div>');
    }

    function update() {
        var pic=document.getElementById('pic').files[0];
        var name=document.getElementById('user').value;
        var formData = new FormData();
        if (pic!=undefined)
            formData.append('pic', pic);
        if (name!='null')
            formData.append('name', name);
        $.ajax({
            url: "/hui/TestController/update.do",
            headers:{
                accessToken:localStorage.getItem('accessToken')
            },
            type: "post",
            data: formData,
            contentType: false,
            processData: false,
            mimeType: "multipart/form-data",
            success: function (data) {
                checkToken(data);
                data=JSON.parse(data);
                localStorage.setItem('accessToken',data.accessToken);
                sessionStorage.setItem('pic',data.result.pic);
                sessionStorage.setItem('name',data.result.name);
                // document.getElementById('userpic').innerHTML='<img class="img-circle" src="images/'+userpic+'" alt="" width="50" height="50">';
                console.log(data);
                console.log(data.result.pic);
                alert('修改成功');
                window.location.reload();
            },
            error: function (data) {
                console.log(data);
                alert('修改失败');
            }
        });

    }

    function update2() {
        var pass=document.getElementById('pass').value;
        var newpass=document.getElementById('newpass').value;
        var newpass2=document.getElementById('newpass2').value;
        $('#erPass0').empty();
        $('#erPass1').empty();
        $('#erPass2').empty();
        if (pass==''){
            $('#erPass0').append('<span style="color: red">原密码不能为空</span>');
            return;
        }
        if (newpass.length<6){
            $('#erPass1').append('<span style="color: red">新密码长度不能少于6位</span>');
            return;
        }
        if (newpass!=newpass2){
            $('#erPass2').append('<span style="color: red">密码不一致</span>');
            return;
        }
        $.ajax({
            url: "/hui/TestController/updatePass.do?pass="+pass+"&newpass="+newpass+'&userid='+userid,
            headers:{
                accessToken:localStorage.getItem('accessToken')
            },
            dataType:'json',
            success: function (data) {
                checkToken(data);
                console.log(data.resMsg);
                // document.getElementById('userpic').innerHTML='<img class="img-circle" src="images/'+userpic+'" alt="" width="50" height="50">';
                if(data.resMsg=='原密码错误')
                    $('#erPass0').append('<span style="color: red">原密码错误</span>');
                else if (data.resMsg=='修改成功') {
                    alert('修改成功');
                    window.location.reload();
                }
                else
                    alert('修改失败');
            },
            error: function (data) {
                console.log(data);
                alert('修改失败');
            }
        });

    }

    function getDepositView() {
        $('#imgs').empty();
        $('#imgslow').empty();
        $('#addHr').empty();
        $('#page').hide();
        $('#imgs').append('<button onclick="showQRCode(1)" class="btn btn-default">1￥</button><span>:3积分</span><br>' +
            '<button  onclick="showQRCode(3)" class="btn btn-default">3￥</button><span>:10积分</span><br>' +
            '<button  onclick="showQRCode(5)" class="btn btn-default">5￥</button><span>:20积分</span>');
    }
    function showQRCode(money) {
        $('#imgs').empty();
        $('#imgslow').empty();
        $('#addHr').empty();
            $('#imgs').append('<img src="/'+money+'.jpg" style="width: 300px;height: 500px"><br> 支付宝用户名:<input type="text" id="aliname"><br><button onclick="confirmPay('+money+')" class="btn btn-default">支付</button> <button class="btn btn-default" onclick="getDepositView()">返回</button>')
        }
        var aliname;
    function confirmPay(money) {
        aliname=document.getElementById('aliname').value;
        if (aliname==''){
            alert('请输入支付宝用户名');
            return;
        }
        if (confirm('支付完成?'))
            deposit(money);
    }
    function deposit(money) {
        var point=0;
        if (money==1)
            point=3;
        if (money==3)
            point=10;
        if (money==5)
            point=20;
            $.ajax({
                url:'/hui/TestController/deposit.do?uid='+userid+'&point='+point+'&money='+money+'&aliname='+aliname,
                headers:{
                    accessToken:localStorage.getItem('accessToken')
                },
                success:function (datas) {
                    checkToken(datas);
                    console.log(datas);
                    if (datas.resMsg=='插入成功')
                        alert('操作成功，将在客服确认后为您添加积分');
                    if (datas.resMsg=='插入失败')
                        alert('操作失败，如已扣费，请联系客服');
                }
            })
    }
    function comOption(comid,comuser) {
        var opid='commentOption'+comid;
        console.log(comid+' |'+comuser);
        if (comuser==userid) {
            console.log('进入')
            if (document.getElementById('jubao'+comid)==null) {
                $('#' + opid).append('<a id="jubao'+comid+'" href="#">举报</a>|');
                $('#' + opid).append('<a href="#" onclick="delCom('+comid+')">删除</a>');
            }else{
                $('#'+opid).empty();
            }
        }else{
            if (document.getElementById('jubao'+comid)==null) {
                $('#' + opid).append('<a id="jubao'+comid+'" href="#">举报</a>');
            }else{
                $('#'+opid).empty();
            }
        }
    }

    function delCom(comid) {
        if (!confirm('确认删除评论?'))
            return;
        $.ajax({
            url:'/hui/TestController/delComments.do?comid='+comid,
            headers:{
                accessToken:localStorage.getItem('accessToken')
            },
            success:function (data) {
                checkToken(data);
                if (data.resMsg!='删除失败'){
                    getComments()
                }else {
                    alert('删除失败');
                }
            }
        })
    }

function skipPages(dataLength) {
            $('#skips').empty();
            pages=parseInt(dataLength/10);
            if (dataLength%10!=0)
                pages+=1;
            console.log('页数是:'+pages);
            var loop=pages;
            loop=loop>5?5:loop;
            console.log('循环次数是:'+pages);
    for (var i = 0; i < loop; i++) {
        if (i == 0) {
            $('#skips').append("                    <li><a id='skip" + i + "' href='#' onclick='skipReady(1)'>first</a></li>"+
                "<li>\n" +
                "                        <a href=\"#\" aria-label=\"Previous\" onclick='skipReady(-1)' id=\"skippre\">\n" +
                "                            <span aria-hidden=\"true\">&laquo;</span>\n" +
                "                        </a>\n" +
                "                    </li>\n");
        }

        $('#skips').append(
            "                    <li><a id='skip" + i + "' href='#' onclick='skipReady(" + (i + 1) + ")'>" + (i + 1) + "</a></li>"
        );
        if (i == loop - 1) {
            if (pages > 5) {
                $('#skips').append(
                    "<li><a>...</a></li>" +
                    "                    <li><a id='skip" + pages + "' href='#' onclick='skipReady(" + pages + ")'>" + pages + "</a></li>")
            }

            $('#skips').append(
                "                    <li>\n" +
                "                        <a id=\"skipnex\" href=\"#\" aria-label=\"Next\" onclick='skipReady(0)'>\n" +
                "                            <span aria-hidden=\"true\">&raquo;</span>\n" +
                "                        </a>\n" +
                "                    </li>"+
                "<li><a id='skip" + i + "' href='#' onclick='skipReady("+pages+")'>end</a></li>");
        }
    }
        }



    function skipReady(page){
        skip(type,page);
    }
</script>

</html>